package io.renren.modules.ccs.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.ccs.entity.RecordUserEntity;
import io.renren.modules.ccs.service.RecordUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author SongR
 * @email 348329560@qq.com
 * @date 2018-07-25 16:03:25
 */
@RestController
@RequestMapping("ccs/recorduser")
public class RecordUserController {
    @Autowired
    private RecordUserService recordUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("ccs:recorduser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = recordUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{recordId}")
    @RequiresPermissions("ccs:recorduser:info")
    public R info(@PathVariable("recordId") Long recordId){
        RecordUserEntity recordUser = recordUserService.selectById(recordId);

        return R.ok().put("recordUser", recordUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("ccs:recorduser:save")
    public R save(@RequestBody RecordUserEntity recordUser){
        recordUserService.insert(recordUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("ccs:recorduser:update")
    public R update(@RequestBody RecordUserEntity recordUser){
        ValidatorUtils.validateEntity(recordUser);
        recordUserService.updateAllColumnById(recordUser);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("ccs:recorduser:delete")
    public R delete(@RequestBody Long[] recordIds){
        recordUserService.deleteBatchIds(Arrays.asList(recordIds));

        return R.ok();
    }

}
